package com.pub.functions;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by IntelliJ IDEA.
 * @author zhuangzhonglong
 * Date: 2008-9-4
 * Time: 13:38:11
 */
public class CryptFuncs {

	public static String getMd5(String text) {
		MessageDigest msgDigest = null;
		try {
			msgDigest = MessageDigest.getInstance("MD5");
		}
		catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		assert msgDigest != null;
		if(text == null) {
			text = "";
		}
		msgDigest.update(text.getBytes());
		byte[] bts = msgDigest.digest();
		String result = StrFuncs.byte2hex(bts);
		return result;
	}

	public static void main(String[] arg) {
		System.out.println("abc MD5: " + CryptFuncs.getMd5("abc"));
	}
}
